#!/bin/bash

counter=0

while true
do
adb wait-for-device

sleep 3

adb root  > /dev/null 

if [ $? -ne 0 ]; then
sleep 5
adb root > /dev/null
if [ $? -ne 0 ]; then
sleep 5
adb root > /dev/null
fi
fi

sleep 40

ifconfig_output=`adb shell "ifconfig usb0"`

echo $ifconfig_output >> log.txt


if [[ $ifconfig_output =~ inet6\ addr:\ ([^f][^e][^0]\S+) ]]; then
    ipv6_address=${BASH_REMATCH[1]}
    echo "IPv6地址: $ipv6_address"

    # 检查IPv6地址是否为全局地址
    if [[ $ipv6_address =~ ^[0-9a-fA-F:]+:[0-9a-fA-F:]+:[0-9a-fA-F:]+:[0-9a-fA-F:]+/ ]]; then
        echo "存在IPv6全局地址。"
    else
        echo "未找到IPv6全局地址。"
    fi
else
    echo "未找到IPv6地址。"
fi

adb reboot

counter=$((counter + 1))

echo $counter

echo "--------------------"

done
